__author__ = """waen <wangjian@21epub.com>"""
__docformat__ = 'restructuredtext'


from AccessControl import ClassSecurityInfo
from zope.interface import implements

from Products.ATContentTypes.content.base import registerATCT

from Products.Archetypes import atapi
from Products.ATContentTypes.content.folder import ATFolderSchema

from Products.ePub.config import PROJECTNAME
from Products.ePub.interfaces import IComixChapter
from Products.ePub.content.folder import ePubFolder
from Products.ePub import ePubMessageFactory as _


# Schema definition
ChapterSchema = ATFolderSchema.copy() + atapi.Schema((
    atapi.StringField('comixisbn',
	                required = True,
					searchable = True,
					widget = atapi.StringWidget(
					    label = _(u'label_info_comixisbn',default=u'Comix ISBN'),
						description = _(u'help_info_comixisbn',default=u'')
					)
	),
	atapi.DateTimeField('onsale',
	                required = False,
					searchable = True,
					widget = atapi.CalendarWidget(
					    label = _(u'label_info_onsale',default=u'On Sale'),
						description = _(u'help_info_onsale',default=u'Please input a on-sale date.')
					)
	),
	atapi.ImageField('cover',
	                required = True,
					default_output_type='image/jpeg',
                    allowable_content_types=('image/*',),
                    sizes= {
                            'mini'    : (200, 200),                            
                    },
					widget = atapi.ImageWidget(
					    label = _(u'label_info_cover',default = u'Cover'),
						description = _(u'help_info_cover',default=u'')
					)	               
	),
    atapi.FloatField('price',
	                required = False,
                    default = 0.00,
					widget = atapi.StringWidget(
					    label=_(u'label_info_price',default=u'Price'),
						description = _(u'help_info_price',default=u'')
					)
	),
))


class ComixChapter(ePubFolder):
    """A chapter,which contains comix pages """
    portal_type      = 'ComixChapter'
    archetype_name   = 'ComixChapter'
    _atct_newTypeFor = {'portal_type' : 'CMF Chapter', 'meta_type' : 'Comix Chapter'}

    implements(IComixChapter)
    schema = ChapterSchema
    def getSeries(self):
	    return self.aq_parent
		
registerATCT(ComixChapter,PROJECTNAME)